from django.db import models
from django.contrib.postgres.fields import ArrayField

import django.utils.timezone as timezone
# Create your models here.
''' # CHANGELOG
1. 将 Maixun 抓取的cuzu相关的数据存储到这个位置
'''

class MaixunCuZuModel(models.Model):
    '''
    存储 Maixun CuZu 的主数据
    '''
    content_type_choices = (
        ('UGC', 'UGC'),
        ('PGC', 'PGC')
    )
    info_category_choices = (
        ('idmi_crawled', 'idmi_crawled'),
        ('maixun_crawled', 'maixun_crawled'),
    )
    id = models.AutoField(primary_key=True)
    create_time = models.DateTimeField(
        verbose_name="create_time",
        editable=True,
        null=False,
        blank=False,
        default=timezone.now
    )
    info_category = models.CharField(
        max_length=20,
        verbose_name="info_category",
        blank=True,
        null=True,
        choices=info_category_choices,
        default='maixun_crawled'
    )
    URL = models.CharField(
        max_length=400,
        verbose_name='URL',
        null=True,
        blank=True,
        default=''
    )
    forum_type_res = ArrayField(
        models.CharField(
            max_length=50,
            verbose_name='forum_type_res',
            null=True,
            blank=True,
            default=''
        )
    )

    content_type = models.CharField(
        max_length=5,
        verbose_name='content_type',
        null=True,
        blank=True,
        default='UGC',
        choices=content_type_choices
    )
    hint_words = models.CharField(
        max_length=100,
        verbose_name='hint_words',
        null=True,
        blank=True,
        default=''
    )
    is_comment = models.IntegerField(
        verbose_name='is_comment',
        null=True,
        blank=True,
        default=0,
        choices=((0, 0), (1, 1))
    )
    target_vehicle_sentence = models.CharField(
        max_length=1000,
        verbose_name='target_vehicle_sentence',
        null=True,
        blank=True,
        default=''
    )
    target_vehicle_sentence_en = models.CharField(
        max_length=3000,
        verbose_name='target_vehicle_sentence_en',
        null=True,
        blank=True,
        default=''
    )
    maixun_title = models.CharField(
        max_length=500,
        verbose_name='maixun_title',
        null=True,
        blank=True,
        default=''
    )
    maixun_text = models.CharField(
        max_length=2000,
        verbose_name='maixun_text',
        null=True,
        blank=True,
        default=''
    )
    website = models.CharField(
        max_length=100,
        verbose_name='website',
        null=True,
        blank=True,
        default=''
    )

    # 下面是脉讯数据对应的字段
    maixun_author_location = models.CharField(
        max_length=50, verbose_name='maixun_author_location',
        null=True, blank=True, default=''
    )
    maixun_domain = models.CharField(
        max_length=50, verbose_name='maixun_domain',
        null=True, blank=True, default=''
    )
    maixun_fid = models.IntegerField(
        verbose_name='maixun_fid',
        default=0
    )
    BodyType = models.CharField(
        max_length=50,
        verbose_name='BodyType',
        null=True,
        blank=True,
        default=''
    )
    Brand = models.CharField(
        max_length=50,
        verbose_name='Brand',
        null=True,
        blank=True,
        default=''
    )
    BrandIndicator = models.CharField(
        max_length=50,
        verbose_name='BrandIndicator',
        null=True,
        blank=True,
        default=''
    )
    FuelType = models.CharField(
        max_length=50,
        verbose_name='FuelType',
        null=True,
        blank=True,
        default=''
    )
    Group = models.CharField(
        max_length=50,
        verbose_name='Group',
        null=True,
        blank=True,
        default=''
    )
    ModelName = models.CharField(
        max_length=50,
        verbose_name='ModelName',
        null=True,
        blank=True,
        default=''
    )
    OEM = models.CharField(
        max_length=50,
        verbose_name='OEM',
        null=True,
        blank=True,
        default=''
    )
    Segment = models.CharField(
        max_length=50,
        verbose_name='Segment',
        null=True,
        blank=True,
        default=''
    )

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'maixuncuzu'
        verbose_name = 'maixuncuzu'
        ordering = ['-id']
        abstract = False


class MaixunCuZuResModel(models.Model):
    '''
    存储 IDMI CuZu 的结果数据
    '''
    id = models.AutoField(primary_key=True)
    cuzu = models.ForeignKey(
        MaixunCuZuModel,
        on_delete=models.CASCADE,
        verbose_name='cuzu_res',
        related_name='cuzu_res'
    )

    cuzu_label_1_int_value = models.IntegerField(
        verbose_name='cuzu_label_1_int_value',
        null=True,
        blank=True,
        default=-1
    )
    cuzu_label_2_int_value = models.IntegerField(
        verbose_name='cuzu_label_2_int_value',
        null=True,
        blank=True,
        default=-1
    )

    content_list_zh = ArrayField(
        models.CharField(
            max_length=500,
            verbose_name='content_list_zh',
            null=True,
            blank=True,
            default=''
        )
    )
    content_list_en = ArrayField(
        models.CharField(
            max_length=500,
            verbose_name='content_list_en',
            null=True,
            blank=True,
            default=''
        )
    )

    sentiment = models.IntegerField(
        verbose_name='sentiment',
        choices=[
            (1, 1),
            (2, 2),
            (3, 3),
            (4, 4),
            (5, 5),
        ],
        default=3
    )

    def __str__(self):
        return f'{self.cuzu.id}'

    class Meta:
        db_table = 'maixuncuzures'
        verbose_name = 'maixuncuzures'
        ordering = ['-id']
        abstract = False




